package com.gl.doc.builder;

import com.gl.doc.model.container.WordXmlContainer;
import com.gl.doc.operation.WordContentRead;
import com.gl.doc.operation.WordOperation;
import com.gl.doc.operation.impl.DefaultWordContentRead;
import com.gl.doc.operation.impl.DefaultWordOperation;

import java.io.File;
import java.io.InputStream;

/**
 * word文档构建
 */
public class WordDocumentBuilder {
    /**
     * word文档操作
     */
    private static final WordOperation wordOperation = new DefaultWordOperation();
    /**
     * word文档内容读取
     */
    private static final WordContentRead wordContentRead = new DefaultWordContentRead();
    /**
     * wordXml存储容器
     */
    private static final WordXmlContainer wordXmlContainer = new WordXmlContainer();

    /**
     * 根据文件对象构建出word文档对象
     *
     * @param file 文件对象
     * @return word文档对象
     */
    public static WordDocument builderWordDocument(File file) {
        WordDocument wordDocument = new WordDocument();
        wordDocument.setWordOperation(wordOperation);
        wordDocument.setWordContentRead(wordContentRead);
        wordDocument.setWordXmlContainer(wordXmlContainer);
        wordDocument.parseWord(file);
        return wordDocument;
    }

    /**
     * 根据文件对象构建出word文档对象
     *
     * @param inputStream 输入流
     * @return word文档对象
     */
    public static WordDocument builderWordDocument(InputStream inputStream) {
        WordDocument wordDocument = new WordDocument();
        wordDocument.setWordOperation(wordOperation);
        wordDocument.setWordContentRead(wordContentRead);
        wordDocument.setWordXmlContainer(wordXmlContainer);
        wordDocument.parseWord(inputStream);
        return wordDocument;
    }
}
